import sqlite3

# Autoincrement

conn = sqlite3.connect("../kookBot.db")

class LiteDb():

    def openDb(self,dbname):
        self.dbname = dbname
        self.conn = sqlite3.connect(self.dbname)
        self.cur = self.conn.cursor()

    def closeDb(self):
        self.cur.close()
        self.conn.close()


    def db_setDice(self,channel_id:int,dice:int):
        d = self.cur.execute(f'select dice from defaultDice where channel_id = {channel_id}').fetchone()
        flg = 0
        if d is None:
            flg = self.cur.execute(f'insert into defaultDice values({channel_id},{dice})')
        else:
            flg = self.cur.execute(f'update  defaultDice set dice ={dice} where channel_id = {channel_id}')
        self.conn.commit()
        return flg.rowcount


    def db_getDice(self,channel_id:int):
        d = self.cur.execute(f'select dice from defaultDice where channel_id = {channel_id}')
        return (d.fetchone()[0])
